package org.jeecg.modules.utils;

import org.springframework.stereotype.Component;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 年月日 时分秒 + 参数随机
 * */
@Component
public class RandomCodeUtils {

    public static String getUUID(){
        UUID uuid  =  UUID.randomUUID();
        String s = uuid.toString();
        int p = 0;
        int j = 0;
        char[] buf = new char[32];
        while(p<s.length()){
            char c = s.charAt(p);
            p+=1;
            if(c=='-')continue;
            buf[j]=c;j+=1;
        }
        return new String(buf);
    }

        //长度18
    public static String getRandomCode(String diy){
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        double random = Math.random()*9999+1000;
        DecimalFormat format = new DecimalFormat("#");
        String code = diy+simpleDateFormat.format(date)+format.format(random);
        return code;
    }

    //长度15
    public static String getRandomCode(){
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHH");
        double random = Math.random()*65000+10000;
        DecimalFormat format = new DecimalFormat("#");
        String code = simpleDateFormat.format(date)+format.format(random);
        return format.format(random);
    }



    //获取4位车桩随机数
    public static String getCheckCode(){
        double random = Math.random()*(9999-1000+1)+1000;
        DecimalFormat format = new DecimalFormat("#");
        String format1 = format.format(random);
        return format1;
    }
    public static String getRandomBikeCode(String diy){

        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyMMddHH");
        double random = Math.random()*(99999-10000+1)+10000;
        DecimalFormat format = new DecimalFormat("#");
        String code = diy+simpleDateFormat.format(date)+format.format(random);
        return code;
    }
    public static String getIcCode(String diy){

        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHH");
        double random = Math.random()*(999-100+1)+100;
        DecimalFormat format = new DecimalFormat("#");
        String code = diy+simpleDateFormat.format(date)+format.format(random);
        return code;
    }

    //IC 卡 随机数
    public static String getICRandomCode(String diy){

        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHH");
        double random = Math.random()*(999999-100000+1)+100000;
        DecimalFormat format = new DecimalFormat("#");
        String code = diy+simpleDateFormat.format(date)+format.format(random);
        return code;
    }

}
